package com.logisticsmanagement.admin_pro;

import java.util.ArrayList;
import java.util.List;

import com.logisticsmanagement.R;
import com.logisticsmanagement.domain.User;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

/**
 * 角色管理功能类
 * 
 * @author 陈朝辉
 * @createTime 2015年3月19日 上午10:31:39
 * @version 1.0
 */
public class RoleManagement extends Fragment {

	private ListView itemRole;
	private List<String[]> userList;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.item_role_management_admin_province, container, false);
		
		itemRole = (ListView) view.findViewById(R.id.listViewRole);
		userList = new ArrayList<String[]>();
		String[] addString = { "1", "asdf", "man", "dafdsfa", "dsaf", "delete" };
		userList.add(addString);

		// 给listView设置适配器
		itemRole.setAdapter(new ListViewRoleAdapter(RoleManagement.this.getActivity(), userList));
		return view;
	}

	private class ViewHolder {
		public TextView tvItemRoleManagementNum;
		public TextView tvItemRoleManagementName;
		public TextView tvItemRoleManagementGender;
		public TextView tvItemRoleManagementDisplayName;
		public Spinner tvItemRoleManagementRoleSpinner;
		public TextView tvItemRoleManagementDelete;
	}

	public class ListViewRoleAdapter extends BaseAdapter {

		private Context context;
		private List list;

		public ListViewRoleAdapter(Context context, List list) {
			this.context = context;
			this.list = list;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int index) {
			// TODO Auto-generated method stub
			return list.get(index);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int index, View view, ViewGroup parent) {
			// TODO Auto-generated method stub
			// 新建viewholder对象
			ViewHolder viewHolder = new ViewHolder();
			if (view == null) {
				view = LayoutInflater.from(context).inflate(
						R.layout.role_item_role_management_admin_province, null);
				viewHolder.tvItemRoleManagementNum = (TextView) view.findViewById(R.id.tvItemRoleManagementNum);
				viewHolder.tvItemRoleManagementName = (TextView) view.findViewById(R.id.tvItemRoleManagementName);
				viewHolder.tvItemRoleManagementGender = (TextView) view.findViewById(R.id.tvItemRoleManagementGender);
				viewHolder.tvItemRoleManagementDisplayName =(TextView) view.findViewById(R.id.tvItemRoleManagementDisplayName);
				viewHolder.tvItemRoleManagementDelete = (TextView) view.findViewById(R.id.tvItemRoleManagementDelete);
				view.setTag(viewHolder);
			}
			else {
				viewHolder = (ViewHolder) view.getTag();
			}
			
			viewHolder.tvItemRoleManagementNum.setText(list.get(0).toString());
			viewHolder.tvItemRoleManagementName.setText(list.get(0).toString());
			viewHolder.tvItemRoleManagementGender.setText(list.get(0).toString());

			return view;
		}

	}

}
